﻿using System;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Users;

namespace DotNetNuke.Modules._2DoTasks.Components.Entities
{
    public class _Project : ContentItem
    {
        public int ProjectId { get; set; }

        public int PortalId { get; set; }

        public int CreatedByUserID { get; set; }

        public DateTime CreatedOnDate { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public Nullable<DateTime> EndDate { get; set; }

        public int LastModifiedUserID { get; set; }

        public DateTime LastModifiedOnDate { get; set; }

        public bool Archived { get; set; }

        /// <summary>
        /// Gets the creation user
        /// </summary>
        public UserInfo CreatedByUser
        {
            get
            {
                if (CreatedByUserID > 0)
                {
                    return UserController.GetUserById(PortalId, CreatedByUserID);
                }
                return null;
            }
        }

        /// <summary>
        /// Gets the last modified user
        /// </summary>
        public UserInfo LastModifiedUser
        {
            get
            {
                if (LastModifiedUserID > 0)
                {
                    return UserController.GetUserById(PortalId, LastModifiedUserID);
                }
                return null;
            }
        }

        #region IHydratable Implementation

        public override void Fill(System.Data.IDataReader dr)
        {
            ProjectId = Convert.ToInt32(dr["Prj_ProjectId"]);

            PortalId = Convert.ToInt32(dr["Prj_PortalId"]);

            CreatedByUserID = Convert.ToInt32(dr["Prj_CreatedByUserId"]);

            CreatedOnDate = Convert.ToDateTime(dr["Prj_CreatedOnDate"]);

            Name = dr["Prj_Name"].ToString();

            Description = dr["Prj_Description"].ToString();

            EndDate = dr["Prj_EndDate"] as Nullable<DateTime>;

            LastModifiedUserID = Convert.ToInt32(dr["Prj_LastModifiedByUserId"]);

            LastModifiedOnDate = Convert.ToDateTime(dr["Prj_LastModifiedOnDate"]);

            Archived = Convert.ToBoolean(dr["Prj_Archived"]);

            //base.FillInternal(dr);  ToDo - Implement Taxonomy
        }

        public override int KeyID
        {
            get
            {
                return ProjectId;
            }
            set
            {
                ProjectId = value;
            }
        }

        #endregion IHydratable Implementation
    }
}